jQuery(document).ready(function ($){

	$('.front .views-slideshow-controls-bottom').css({'opacity':'0'});
	$('.front .slide-caption').css({'opacity':'0'});

	//For More Projects, Color Image fades in and out
	$("#more-projects li").hover(
		//Hover Over
		function(){
			$(this).find('.color').css({'opacity':'0','display':'block'}).animate({opacity:1},400);},
		//Hover Out
		function(){$(this).find('.color').css({'opacity':'1'}).animate({opacity:0},300);}
	);
	
	//Home Page Overlay Controls
	$("#home-page-slideshow").hover(
		//Hover Over
		function(){
			$(this).find('.slide-caption').stop().css({'opacity':'0','display':'block'}).animate({opacity:1},400);
			$('.views-slideshow-controls-bottom').stop().animate({opacity:1},400);},
		//Hover Out
		function(){
			$(this).find('.slide-caption').stop().css({'opacity':'1'}).animate({opacity:0},300);
			$('.views-slideshow-controls-bottom').stop().animate({opacity:0},300);}
	);
	
	//Add target=_blank for Twitter block
	$('#site-tweets > ul li a[href]').attr({
    	target: "_blank", 
        title: "Opens in a new window"
    });
    
    //Accordion for side menu
      var allPanels = $('#sidebar-first .submenu');
      var url = window.location.pathname.split( '/' );
	  urlClass = "." + url[1];
	  
	  if(!url[1]||url[1]=="clients"){
	  	urlClass = ".cause";
	  }
	  
	  $(urlClass).show();
	  
	  $('#sidebar-first .section-title a.active').parent().next('.submenu').show();
	        
	  $('#sidebar-first .section-title a').click(function() {
      	$this = $(this);
     	 $target =  $this.parent().next();
      
     	if(!$target.hasClass('active')){
         	allPanels.removeClass('active').slideUp();
         	$target.addClass('active').slideDown();
      	}
        if(!$target.hasClass('clients')){
	    	return false;
	    }
  		});
  		
  		//Clearfield (used for forms)
  		$('input[type="text"]').clearField({blurClass: 'blurred'});
  		$('textarea').clearField({blurClass: 'blurred'});
  		
  		//Move the Sharethis block to align with blue line above content
  		$('.node-type-projects #sharethis-sharethis').appendTo('.project-header');
  		$('.node-type-projects #sharethis-sharethis').css({
  			'bottom':'0',
  			'top':'auto',
  		})

  		//Timeline Flag
  		$('.timeline-flag').click(function(){
   			$(this).find('span').animate({opacity:1,left:'-140px'},500);
  		});
  		
  		//Move the Tag Banner in the Project Details
  		if($('.tag-banner')){
  			$('.tag-banner').show();
	  		var tagwidth = -1 * $('.tag-banner').width();
  			var tagPos = $('.tag-banner').position();
  			var newXPos = -1*tagPos.left - 50;
  			$('.tag-banner').css({left:newXPos})
  		}
});

/**
 * jQuery-Plugin "clearField"
 * 
 * @version: 1.1, 04.12.2010
 * 
 * @author: Stijn Van Minnebruggen
 *          stijn@donotfold.be
 *          http://www.donotfold.be
 * 
 * @example: $('selector').clearField();
 * @example: $('selector').clearField({ blurClass: 'myBlurredClass', activeClass: 'myactiveClass' });
 * 
 */
	
	(function($){$.fn.clearField=function(s){s=jQuery.extend({blurClass:'clearFieldBlurred',activeClass:'clearFieldActive',attribute:'rel',value:''},s);return $(this).each(function(){var el=$(this);s.value=el.val();if(el.attr(s.attribute)==undefined){el.attr(s.attribute,el.val()).addClass(s.blurClass)}else{s.value=el.attr(s.attribute)}el.focus(function(){if(el.val()==el.attr(s.attribute)){el.val('').removeClass(s.blurClass).addClass(s.activeClass)}});el.blur(function(){if(el.val()==''){el.val(el.attr(s.attribute)).removeClass(s.activeClass).addClass(s.blurClass)}})})}})(jQuery);

//Facebook Like
(function(d, s, id) {
	var js, fjs = d.getElementsByTagName(s)[0];
	if (d.getElementById(id)) return;
	js = d.createElement(s); js.id = id;
	js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
	fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

//Tweeter Button
!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");

//